/**
 * ajax请求配置
 */
import axios from 'axios'
import Qs from 'qs'

//import cookie from '../../static/js/cookie.js'

// axios默认配置
axios.defaults.timeout = 10000; // 超时时间

// //整理数据
 axios.defaults.transformRequest = function (data) {
   data = Qs.stringify(data,{ indices: false });
   return data;
};

// 路由请求拦截
// http request 拦截器
axios.interceptors.request.use(
  config => {
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

    return config;
  },
  error => {
    return Promise.reject(error.response);
  });

// 路由响应拦截
// http response 拦截器
axios.interceptors.response.use(
  response => {
    if (response.data.resultCode == "404") {
      console.log("response.data.resultCode是404")
      return
    } else {
      return response;
    }
  },
  error => {
    return Promise.reject(error.response) // 返回接口返回的错误信息
  });
export default axios;
